package com.cp.helper.controller;

import com.cp.helper.bean.Birthday;
import com.cp.helper.dao.impl.BirthdayDao;
import com.cp.helper.enums.BirthTypeEnum;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.datetime.joda.DateTimeParser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * @描述:
 * @Author : chenpeng
 * @Date : 2015/10/14 17:03
 */
@Controller
@RequestMapping("/birth")
public class BirthdayController {

    @Autowired
    private BirthdayDao birthdayDao;

    @RequestMapping("/get_birth_list")
    @ResponseBody
    public Object getBirthdayList(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("result",birthdayDao.selectList(null));
        return map;

    }
    @RequestMapping("/add_birthday")
    @ResponseBody
    public Object addBirthday(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        Birthday birthday = new Birthday();
        birthday.setOwnerId(1);
        birthday.setBirthDate(DateUtils.parseDate("1990-09-14", new String[]{"yyyy-MM-dd"}));
        birthday.setBirthYear(1990);
        birthday.setBirthMonth(11);
        birthday.setBirthDay(9);
        birthday.setBirthType(BirthTypeEnum.Gregorian_calendar.getCode());
        int count = birthdayDao.insert(birthday);
        System.out.println(count);
        return map;
    }

    @RequestMapping("/delete_birthday")
    @ResponseBody
    public Object deleteBirthday(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        int id = 1;
        birthdayDao.delete(id);
        return map;

    }
}
